{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>文章列表</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-2" style="width: 100px">
                        <div class="input-group">
                            <a href="{:url('add_article')}">
                                <button class="btn btn-outline btn-primary" type="button">添加文章</button>
                            </a>
                        </div>
                    </div>
                    <form name="admin_list_sea" class="layui-form" method="post" action="">
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" id="key" class="form-control" name="key" value=""
                                       placeholder="输入需查询的名称"/>
                                <span class="input-group-btn"> 
                                    <button type="submit" class="btn btn-primary" lay-submit lay-filter="search"><i
                                            class="fa fa-search"></i> 搜索</button>
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-table"
                           lay-data="{height:'full-210',url:'index',method:'post',page:true,limit:20,id:'article'}"
                           lay-filter="article">
                        <thead>
                        <tr>
                            <th lay-data="{title:'ID',field:'id',fixed:true,align:'center',sort:true,width:60}"></th>
                            <th lay-data="{title:'标题',field:'title',width:250}"></th>
                            <th lay-data="{title:'所属分类',field:'name',width:100}"></th>
                            <th lay-data="{title:'文章封面',field:'photo',width:100,templet:'#photo',align:'center'}"></th>
                            <th lay-data="{title:'显示',field:'status',width:100,templet:'#status',align:'center',sort:true}"></th>
                            <th lay-data="{title:'推荐',field:'is_tui',width:100,templet:'#is_tui',align:'center',sort:true}"></th>
                            <th lay-data="{title:'热门',field:'is_re',width:100,templet:'#is_re',align:'center',sort:true}"></th>
                            <th lay-data="{title:'浏览量',field:'views',width:100,align:'center',sort:true}"></th>
                            <th lay-data="{title:'创建时间',field:'create_time',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'更新时间',field:'update_time',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'操作',field:'id',width:150,toolbar:'#toolbar',align:'center',fixed:'right'}"></th>
                        </tr>
                        </thead>
                    </table>
                    <script type="text/html" id="photo">
                        <img src="/static/uploads/images/{{d.photo}}" style="height: 28px"
                             onerror="this.src='/static/admin/images/no_img.jpg'"/>
                    </script>

                    <script type="text/html" id="status">
                        <!-- 这里的 checked 的状态只是演示 -->
                        <input type="checkbox" name="status" value="{{d.id}}"  lay-skin="switch" lay-text="是|否" lay-filter="status"
                               {{d.status==1?'checked':''}}>
                    </script>
                    <script type="text/html" id="is_tui">
                        <input type="checkbox" name="is_tui" value="{{d.id}}"  lay-skin="switch" lay-text="是|否" lay-filter="is_tui"
                               {{d.is_tui==1?'checked':''}}>
                    </script>
                    <script type="text/html" id="is_re">
                        <input type="checkbox" name="is_re" value="{{d.id}}"  lay-skin="switch" lay-text="是|否" lay-filter="is_re"
                               {{d.is_re==1?'checked':''}}>
                    </script>
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-group">
                            <button onclick="edit_article({{d.id}})" class="layui-btn layui-btn-xs">
                                <i class="fa fa-paste"></i> 编辑
                            </button>&nbsp;&nbsp;
                            <button onclick="del_article({{d.id}})" class="layui-btn layui-btn-danger layui-btn-xs">
                                <i class="fa fa-trash-o"></i> 删除
                            </button>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<!-- 加载动画 -->
<div class="spiner-example">
    <div class="sk-spinner sk-spinner-three-bounce">
        <div class="sk-bounce1"></div>
        <div class="sk-bounce2"></div>
        <div class="sk-bounce3"></div>
    </div>
</div>

{include file="public/footer" /}

<script type="text/javascript">
    $(".spiner-example").css('display', 'none'); //数据加载完关闭动画
    var form = layui.form, table = layui.table;

    form.on('submit(search)', function (data) {
        var data = data.field;
        table.reload('article', {
            where: data
        });
        return false;
    });

    //编辑文章
    function edit_article(id) {
        location.href = './edit_article/id/' + id;
    }

    //删除文章
    function del_article(id) {
        lunhui.confirm(id, '{:url("del_article")}');
    }

    /**
     * 文章状态
     */
    form.on('switch(status)', function (obj) {
        $.post("{:url('article_state')}", {id: this.value}, function (result) {
            //layer.tips(result.msg, obj.othis, {tips: 4});
        });
    });
    /**
     * 推荐状态
     */
    form.on('switch(is_tui)', function (obj) {
        $.post("{:url('article_is_tui')}", {id: this.value}, function (result) {
        //     //layer.tips(result.msg, obj.othis, {tips: 4});
        });
    });
    /**
     * 热门状态
     */
    form.on('switch(is_re)', function (obj) {
        $.post("{:url('article_is_re')}", {id: this.value}, function (result) {
        //     //layer.tips(result.msg, obj.othis, {tips: 4});
        });
    });
</script>
</body>
</html>